package com.tarena.security.admin.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tarena.security.admin.entity.db.UserRole;
import com.tarena.security.admin.param.UpdateUserRoleParam;
import com.tarena.security.admin.param.UserRoleParam;
import com.tarena.security.admin.query.UserRoleQuery;
import com.tarena.security.admin.result.JsonResult;
import com.tarena.security.admin.service.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * user_role 前端控制器
 * </p>
 *
 * @author Ly
 * @since 2023-04-10
 */
@RestController
@RequestMapping("/userRole")
@Api(tags = "用户角色控制器")
@Slf4j
public class UserRoleController {
    @Autowired
    IUserRoleService userRoleService;
    // 添加用户角色
    @ApiOperation("新增用户角色")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated UserRoleParam userRoleParam){
       log.info("收到前端的UserRoleParam:{}",userRoleParam);
       userRoleService.insertOne(userRoleParam);
        return JsonResult.ok();
    }

    // 查询用户角色
    @ApiOperation("查询用户角色")
    @PostMapping("/select-userRole")
    public JsonResult<UserRole> selectByuserId( Integer userId){
        log.info("userId:{}",userId);
        UserRole u=userRoleService.selectOne(userId);
        log.info("u:{}",u);
        return JsonResult.ok(u);
    }

    // 删除用户角色
    @ApiOperation("删除用户角色")
    @PostMapping("/delete-userRole")
    public JsonResult<Void> deleteByuserId( Integer userId){
        log.info("userId:{}",userId);
        userRoleService.deleteOneByUserId(userId);
        return JsonResult.ok();
    }

    // 修改用户角色
    @ApiOperation("修改用户角色")
    @PostMapping("/update-userRole")
    public JsonResult<Void> updateByuserRole(@Validated UpdateUserRoleParam updateUserRoleParam){
        log.info("UserRoleParam:{}",updateUserRoleParam);
        userRoleService.updateByuserRole(updateUserRoleParam);
        return JsonResult.ok();
    }
}
